package com.robot.member.dao;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;

import com.robot.member.pojo.Feedback;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.transaction.annotation.Transactional;

/**
 * feedback数据访问接口
 *
 * @author
 */
public interface FeedbackDao extends JpaRepository<Feedback, String>, JpaSpecificationExecutor<Feedback> {
    /**
     * 所有反馈并分页
     *
     * @param pageable
     * @return
     */
    public Page<Feedback> findAllByDeletedAtNullOrderByCreatedAt(Pageable pageable);

    /**
     * 根据memberId查会员的所有反馈并分页
     *
     * @param memberId
     * @param pageable
     * @return
     */
    public Page<Feedback> findAllByMemberIdOrderByCreatedAt(String memberId, Pageable pageable);

    /**
     * 根据id和memberId查会员的某一反馈详情
     *
     * @param id
     * @param memberId
     * @return
     */
    public Feedback findByIdAndMemberId(String id, String memberId);

    /**
     * 软删除
     *
     * @param id
     */
    @Transactional(rollbackFor = Exception.class)
    @Modifying
    @Query(value = "update member.feedback set member.feedback.deleted_at=now() where member.feedback.id=?", nativeQuery = true)
    public void updateFeedbackById(String id);

}
